﻿using System;
using System.Collections.Generic;
using System.Text;
using Close.Controls;
using Close.Properties;
using Close.Data;

namespace Close.controls.MenuPanels
{
    class GameDetail : NotifyItemBase
    {

        public UInt16 Id { get; set; }
        public Double TimeElapsed { get; set; }
        public DateTime LastPlayedDate { get; set; }
        public byte State { get; set; }
        
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="id">game id</param>
        /// <param name="playedTime">total time</param>
        /// <param name="date">last played</param>
        /// <param name="state">game state (playing, unsolved, solved)</param>
        public GameDetail(UInt16 id, Double playedTime, DateTime date, byte state)
        {
            this.Id = id;
            this.TimeElapsed = playedTime;
            this.LastPlayedDate = date;
            this.State = state;
        }

        public string StateString
        {
            get
            {
                switch (State)
                {
                    case (byte)GameStates.InProgess:
                        return Resources.StateResi;
                    case (byte)GameStates.Completed:
                        return Resources.StateVyreseno;
                    case (byte)GameStates.NotPlayed:
                        return Resources.StateNereseno;
                    default:
                        throw new ApplicationException("Incorrect game state");
                }
            }
        }
        public string TimeElapsedString
        {
            get
            {
                TimeSpan elapsedTime = TimeSpan.FromSeconds(TimeElapsed);
                if (elapsedTime.Hours == 0)
                    return String.Format("{1}:{2}", elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds.ToString("00"));
                else
                    return String.Format("{0}:{1}:{2}", elapsedTime.Hours, elapsedTime.Minutes.ToString("00"), elapsedTime.Seconds.ToString("00"));
            }
        }
        public string LastPlayedDateString
        {
            get
            {
                if (LastPlayedDate.Equals(DateTime.MinValue))
                    return String.Empty;
                else
                    return LastPlayedDate.ToString();
            }
        }
    }
}
